import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiNavigationPage(Base):
    """
    语音训练导航技能页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.navigation_home_btn = (By.XPATH, Yomi.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.navigation_back_btn = (By.XPATH, Yomi.RESOURCE_ID.format('ivBack'))

        # 语音搜索按钮
        self.navigation_voice_search_btn = (By.XPATH, Yomi.RESOURCE_ID.format("tv_start_voice_search"))

        # 搜索地点
        self.navigation_search_input = (By.XPATH, Yomi.RESOURCE_ID.format("et_normal_content"))

        # 立即搜索按钮
        self.navigation_search_now_btn = (By.XPATH, Yomi.RESOURCE_ID.format("search_now"))

        # 服务tab名称
        self.navigation_service_tab_name_text = (By.XPATH, Yomi.service_tab_name_text.format(""))

        # 服务tab选中框
        self.navigation_tab_select_icon = (By.XPATH, Yomi.service_tab_select_icon.format(""))

        # 城市图标
        self.navigation_city_icon = (By.XPATH, Yomi.city_icon.format(""))

        # 城市地址详细
        self.navigation_city_address_detailed_text = (By.XPATH, Yomi.city_address_detailed_text.format(""))

        # 城市地址
        self.navigation_city_address_text = (By.XPATH, Yomi.city_address_text.format(""))

        # 定位图标
        self.navigation_positioning_icon = (By.XPATH, Yomi.RESOURCE_ID.format("btn_location"))

        # 缩小按钮
        self.navigation_zoom_out_btn = (By.XPATH, Yomi.RESOURCE_ID.format("btn_scale_down"))

        # 放大按钮
        self.navigation_zoom_in_btn = (By.XPATH, Yomi.RESOURCE_ID.format("btn_scale_up"))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.navigation_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.navigation_home_btn)

    def click_voice_search(self):
        """
        点击语音搜索按钮

        :return:None
        """
        self.click_element(self.navigation_voice_search_btn)

    def input_search(self, index):
        """
        输入搜索地点

        index 为输入的地点
        :return:None
        """
        self.input_text(self.navigation_search_input, index)

    def click_search_now(self):
        """
        点击立即搜索按钮

        :return:None
        """
        self.click_element(self.navigation_search_now_btn)

    def get_service_tab_name(self, index=1):
        """
        获取服务tab名称

        :return:获取元素
        """
        self.navigation_service_tab_name_text = (By.XPATH, Yomi.service_tab_name_text.format(index))
        return self.find_element_o(self.navigation_service_tab_name_text)

    def click_service_tab_name(self, index=1):
        """
        点击服务tab名称

        :return:None
        """
        self.navigation_service_tab_name_text = (By.XPATH, Yomi.service_tab_name_text.format(index))
        self.click_element(self.navigation_service_tab_name_text)

    def get_tab_select(self, index=1):
        """
        获取服务tab选中icon

        :return:获取元素
        """
        self.navigation_tab_select_icon = (By.XPATH, Yomi.service_tab_select_icon.format(index))
        return self.find_element_o(self.navigation_tab_select_icon)

    def get_city(self, index=1):
        """
        获取城市图标

        :return:获取元素
        """
        self.navigation_city_icon = (By.XPATH, Yomi.city_icon.format(index))
        return self.find_element_o(self.navigation_city_icon)

    def get_city_address_detailed(self, index=1):
        """
        获取城市地址详细

        :return:获取元素
        """
        self.navigation_city_address_detailed_text = (By.XPATH, Yomi.city_address_detailed_text.format(index))
        return self.find_element_o(self.navigation_city_address_detailed_text)

    def click_city_address_detailed(self, index=1):
        """
        点击城市地址详细

        :return:获取元素
        """
        self.navigation_city_address_detailed_text = (By.XPATH, Yomi.city_address_detailed_text.format(index))
        self.click_element(self.navigation_city_address_detailed_text)

    def get_city_address(self, index=1):
        """
        获取城市地址

        :return:获取元素
        """
        self.navigation_city_address_text = (By.XPATH, Yomi.city_address_text.format(index))
        return self.find_element_o(self.navigation_city_address_text)

    def click_city_address(self, index=1):
        """
        点击城市地址

        :return:获取元素
        """
        self.navigation_city_address_text = (By.XPATH, Yomi.city_address_text.format(index))
        self.click_element(self.navigation_city_address_text)

    def click_positioning(self):
        """
        点击定位图标

        :return:None
        """
        self.click_element(self.navigation_positioning_icon)

    def click_zoom_out(self):
        """
        点击缩小按钮

        :return:None
        """
        self.click_element(self.navigation_zoom_out_btn)

    def click_zoom_in(self):
        """
        点击放大按钮

        :return:None
        """
        self.click_element(self.navigation_zoom_in_btn)

    def swipe_navigation_list(self):
        """
        滑动城市列表

        :return:None
        """
        self.swipe_o(location=(500, 500, 332, 700), direction='up')

    def is_display_yomi_navigation(self):
        """
        查看是否进入语音训练导航
        :return:
        """
        return self.is_display(self.navigation_voice_search_btn)
